<?php

namespace Shared\Doctrine\Mysql\StringFunction;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;

/**
 * DATEFunction ::= "YEAR" "(" StringPrimary ")"
 */
class Year extends FunctionNode {

	public $stringExpression;

	public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
		return 'YEAR(' . $this->stringExpression->dispatch($sqlWalker) . ')';
	}

	public function parse(\Doctrine\ORM\Query\Parser $parser) {
		//$lexer = $parser->getLexer();

		$parser->match(\Doctrine\ORM\Query\Lexer::T_IDENTIFIER);
		$parser->match(\Doctrine\ORM\Query\Lexer::T_OPEN_PARENTHESIS);
		$this->stringExpression = $parser->StringExpression();
		$parser->match(\Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS);
	}

}
